package com.example.web.controller;

import com.example.web.service.CategoryService;
import com.example.xo.pojo.Category;
import com.example.xo.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@RequestMapping("web")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @PostMapping("add")
    public Result add(Category category){
        if (category.getCategoryName()==null||category.getCategoryName().trim().length()==0){
            log.info("分类名是空");
            return Result.error();
        }
        if (category.getCategoryName().length()>20){
            log.info("分类名过长");
            return Result.error();
        }


        boolean add = categoryService.add(category);
        return Result.success(add);
    }


}
